package com.sx.jys.app.net.bean

import com.blankj.utilcode.util.TimeUtils
import com.sx.jys.app.until.toColor

data class OrderBean(
    var code: String? = null,
    var orderType: String? = null,//1-做多 2-做空
    var openTime: String? = null,
    var creationTime: String? = null, //下单时间
    var profit: String? = null,//利润
    var status: String? = null, //下单类型 0-未平仓 1-已平仓
    var login: String? = null, //名字
    var bidPrice: String? = null, //实际买入
    var lever: String? = null, //杠杆
    var numbers: String? = null, //数量(张或者u)
    var closePrice: String? = null, //平仓价
    var closeTime: String? = null, //平仓时间
    var closedNumbers: String? = null, //已成交数量
    var usdtNumbers: String? = null, //保证金数量
    var closedUsdt: String? = null, //已成交金额
    var isOneOrder: String? = null, //1-手动下单 0-策略下单
    var closingType: String? = null, //平仓方式：1-盈利平仓 2-止损平仓 3-预止损平仓 4-时间平仓
    var stopProfit: String? = null, //录单止盈价
    var loseProfit: String? = null, //录单止损价
    var ldLogin: String? = null, //录单账号
    var feek: String? = null, //开仓手续费
    var feep: String? = null, //平仓手续费
) {
    fun orderTypeStr():String{
        isOneOrder?.let {
           return if ("1".equals(it)){
                "人工(${ldLogin.orEmpty()})"
            }else{
                "策略"
            }
        }
        return ""
    }

    fun orderTypeStr2():String{
        isOneOrder?.let {
            return if ("1".equals(it)){
                "手动下单"
            }else{
                "策略下单"
            }
        }
        return ""
    }

    fun getStatusStr() =
        if ("0".equals(status)) {
            "未平仓"
        } else if ("1".equals(status)) {
            "已平仓"
        } else if("5".equals(status)){
            "已撤销"
        }else{
            "未知状态${status}"
        }

    fun closingTypeStr(): String? {
        closingType?.let {
            return when (it) {
                "1" -> "盈利平仓"
                "2" -> "止损平仓"
                "3" -> "预止损平仓"
                "4" -> "时间平仓"
                else -> ""
            }
        }
        return ""
    }

    fun getTimeStr(): String? {
        openTime?.toLong()?.let {
            var format = "yyyy-MM-dd HH:mm:ss"
            val date = TimeUtils.millis2Date(it)
            return TimeUtils.date2String(date, format)
        }
        return ""
    }

    fun getTypeStr(): String {
        return if ("1".equals(orderType)) {
            "做多"
        } else if ("2".equals(orderType)) {
            "做空"
        } else {
            "未知类型"
        }
    }

    fun getTypeColor(): Int {
        return if ("1".equals(orderType)) {
            "1".toColor()
        } else if ("2".equals(orderType)) {
            "-1".toColor()
        } else {
            "1".toColor()
        }
    }
}